if(!this.mecoolNotify){
	this.mecoolNotify={};
}
(
	function(){
		$.pnotify.defaults.styling = "jqueryui";
		$.pnotify.defaults.history = false;
		$.pnotify.defaults.width = "140px";
		var fetchUrl="message/fetchNotifications.html";
		var notice;
		var noticeOptions={
							    text: "",
							    addclass: 'globalText',
							    icon: 'ui-icon ui-icon-mail-closed',
							    hide: false,
						    	sticker: false,
						    	after_close: function(pnotify) {
						    		notice=undefined;
							    }
							};
		
		function pull(){
			$.getJSON(fetchUrl, function(jsonData){
				if(jsonData.success){
					var msgNum=jsonData.extraData.msgNum;
					if(msgNum>0){
						if(notice){
							noticeOptions.text=getText(msgNum);
							notice.pnotify(noticeOptions);
						}else{
							mecoolNotify.popNofity(msgNum);
						}
					}else{
						$.pnotify_remove_all();
						notice=undefined;
					}
					
					setTimeout(function() {
						mecoolNotify.pullNofity()
					}, 5000);
				}
			});
		}
		
		function getText(num){
			return '<a onclick="mecoolNotify.openNotifyPage();" href="javascript:;">'+num+'条未读消息</a>';
		}
		
		mecoolNotify.openNotifyPage=function(){
			changeTab("4");
			window.open ("message/messageMain.html?open=messageList", "main");
		}
		
		
		mecoolNotify.pullNofity=function(){
			setTimeout(pull,1000);
		}
		
		mecoolNotify.popNofity=function(msgNum){
			noticeOptions.text=getText(msgNum);
			notice=$.pnotify(noticeOptions);
		}
	}
	()
)

$(function(){
	mecoolNotify.pullNofity();
});
